package com.googlecode.lazyrecords.berkeleydb;

import com.googlecode.totallylazy.Closeables;
import com.googlecode.totallylazy.Sequence;
import com.sleepycat.je.Database;
import com.sleepycat.je.SecondaryDatabase;

import java.io.Closeable;
import java.io.IOException;

public class Table implements Closeable{
    private final Database primary;
    private final Sequence<SecondaryDatabase> secondary;

    public Table(final Database primary, final Sequence<SecondaryDatabase> secondary) {
        this.primary = primary;
        this.secondary = secondary;
    }

    public Database primary() {
        return primary;
    }

    public Sequence<SecondaryDatabase> secondary() {
        return secondary;
    }

    @Override
    public void close() throws IOException {
        secondary().each(Closeables.close());
        primary().close();
    }
}
